package zengjin.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zengjin.common.PageResponse;
import zengjin.common.R;
import zengjin.model.dto.report.AddReportRequest;
import zengjin.model.dto.report.PageReportRequest;
import zengjin.model.dto.report.UpdateReportRequest;
import zengjin.model.vo.report.PageReportVO;
import zengjin.model.vo.report.ReportVO;
import zengjin.service.ReportService;

/**
 * @author 19324
 */
@Tag(name = "举报相关接口")
@RestController
@RequestMapping("/report")
@Slf4j
public class ReportController {


    @Resource
    private ReportService reportService;

    //1.添加举报
    @Operation(summary = "添加举报")
    @PostMapping("/addReport")
    public R<Boolean> addReport(@RequestBody AddReportRequest addReportRequest) {
        if (addReportRequest == null) {
            throw new RuntimeException("参数为空");
        }
        boolean result = reportService.addReport(addReportRequest);
        if (!result) {
            throw new RuntimeException("添加失败");
        }
        return R.success(true, "添加成功");
    }

    //2.修改举报
    @Operation(summary = "修改举报")
    @PostMapping("/updateReport")
    public R<Boolean> updateReport(@RequestBody UpdateReportRequest updateReportRequest) {
        if (updateReportRequest == null) {
            throw new RuntimeException("参数为空");
        }
        boolean result = reportService.updateReport(updateReportRequest);
        if (!result) {
            throw new RuntimeException("修改失败");
        }
        return R.success(true, "修改成功");

    }

    //3.分页查询举报
    @Operation(summary = "分页查询举报")
    @PostMapping("/pageQueryReport")
    public R<PageResponse<PageReportVO>> pageQueryReport(@RequestBody PageReportRequest pageReportRequest) {
        if (pageReportRequest == null) {
            throw new RuntimeException("参数为空");
        }
        PageResponse<PageReportVO> result = reportService.pageQueryReport(pageReportRequest);
        if (result == null) {
            return R.error(null, "分页查询失败");
        }
        return R.success(result, "分页查询成功");

    }

    //4.删除举报
    @Operation(summary = "删除举报")
    @PostMapping("/deleteReport")
    public R<Boolean> deleteReport(Long reportId) {
        if (reportId == null) {
            throw new RuntimeException("参数为空");
        }
        boolean result = reportService.deleteReport(reportId);
        if (!result) {
            throw new RuntimeException("删除失败");
        }
        return R.success(true, "删除成功");
    }

    //5.查询举报详情
    @Operation(summary = "查询举报详情")
    @PostMapping("/queryReportDetail")
    public R<ReportVO> queryReportDetail(Long reportId) {
        if (reportId == null) {
            throw new RuntimeException("参数为空");
        }
        ReportVO result = reportService.queryReportDetail(reportId);
        if (result == null) {
            return R.error(null, "查询失败");
        }
        return R.success(result, "查询成功");
    }


}
